package com.example.cloud.controller.personal;

import com.example.cloud.controller.common.BaseController;
import com.example.cloud.model.dto.QueryModel;
import com.example.cloud.model.dto.Result;
import com.example.cloud.model.personal.AttendanceRecord;
import com.example.cloud.service.personal.RelaxationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by wangtao on 2018/5/22.
 */
@RestController
@RequestMapping("/relaxation")
public class RelaxationController extends BaseController {

    private Logger logger = LoggerFactory.getLogger(RelaxationController.class);

    @Autowired
    private RelaxationService relaxationService;

    @PostMapping("/search")
    public Result search(@RequestBody QueryModel model) {
        StringBuilder sql = new StringBuilder();
        sql.append("select t1.*,DATE_FORMAT(t1.start_time,'%Y-%m-%d %H:%i') as starttime, DATE_FORMAT(t1.end_time,'%Y-%m-%d %H:%i') as endtime," +
                " DATE_FORMAT(t2.start_time,'%Y-%m-%d %H:%i') as leavestarttime, DATE_FORMAT(t2.end_time,'%Y-%m-%d %H:%i') as leaveendtime");
        sql.append(" from attendance_record t1, attendance_record t2");
        sql.append(" where t1.parent_id = t2.id");
        return this.multiQuery(model, sql, AttendanceRecord.class);
    }
}
